// import axios from "axios";
// import api from "@/api";
// import { toLogout, systemPrivilegeInfo } from "../../api/api";
const media = {
  state: {
    navlist: [], // 菜单列表
    openeds: [],
    allPlayMedia: []
  },
  mutations: {
    SET_navlist: (state, navlist) => {
      state.navlist = navlist || [];
    },
    SET_openeds: (state, openeds) => {
      state.openeds = openeds;
    },
    SET_allPlayMedia: (state, allPlayMedia) => {
      state.allPlayMedia = allPlayMedia;
    }
  },
  actions: {
    async SET_navlist({ commit }, data) {
      // console.log("SET_navlist", data);
      commit("SET_navlist", data);
    },
    async UPDATE_allPlayMedia({ state }, data) {
      if (data.length === 1) {
        state.allPlayMedia.splice(data, 1);
      } else {
        const index1 = data[0];
        const index2 = data[1];
        const temp = state.allPlayMedia[index1];
        state.allPlayMedia[index1] = state.allPlayMedia[index2];
        state.allPlayMedia[index2] = temp;
      }
    },
    async SET_openeds({ commit, state }, data) {
      // console.log("SET_openeds", data);
      commit("SET_openeds", data);
      // 全部播放记录
      const allPlayMedia = [...state.allPlayMedia];
      data.forEach((item) => {
        // console.log("item000", state.allPlayMedia);
        // console.log("item000", item);
        const flag = allPlayMedia.indexOf(item) === -1;
        if (flag) {
          allPlayMedia.unshift(item);
        }
      });
      // console.log("allPlayMedia", allPlayMedia);
      commit("SET_allPlayMedia", allPlayMedia);
    }
  }
};
export default media;
